<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>用户注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #f5f5f5;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
        }
        
        .register-container {
            background: white;
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            padding: 40px;
            width: 100%;
            max-width: 450px;
            text-align: center;
            border: 1px solid #e5e5e5;
        }
        
        .logo {
            font-size: 32px;
            font-weight: bold;
            color: #1a1a1a;
            margin-bottom: 10px;
        }
        
        .subtitle {
            color: #666;
            margin-bottom: 30px;
            font-size: 14px;
        }
        
        .form-group {
            margin-bottom: 20px;
            text-align: left;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #1a1a1a;
            font-weight: 600;
            font-size: 14px;
        }
        
        .form-group input {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e5e5e5;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: #fafafa;
            color: #1a1a1a;
        }
        
        .form-group input:focus {
            outline: none;
            border-color: #333;
            background: #fff;
            box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
        }
        
        .form-group input.error {
            border-color: #d32f2f;
        }
        
        .register-btn {
            width: 100%;
            padding: 14px;
            background: #1a1a1a;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 10px;
        }
        
        .register-btn:hover {
            background: #333;
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        }
        
        .register-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }
        
        .error-message {
            background: #ffebee;
            color: #c62828;
            padding: 12px;
            border-radius: 8px;
            margin-bottom: 20px;
            border-left: 4px solid #f44336;
            font-size: 14px;
        }
        
        .login-link {
            margin-top: 25px;
            color: #666;
            font-size: 14px;
        }
        
        .login-link a {
            color: #1a1a1a;
            text-decoration: none;
            font-weight: 600;
        }
        
        .login-link a:hover {
            text-decoration: underline;
        }
        
        .divider {
            margin: 20px 0;
            display: flex;
            align-items: center;
            color: #999;
            font-size: 12px;
        }
        
        .divider::before,
        .divider::after {
            content: '';
            flex: 1;
            height: 1px;
            background: #e5e5e5;
        }
        
        .divider::before {
            margin-right: 10px;
        }
        
        .divider::after {
            margin-left: 10px;
        }
        
        .password-strength {
            margin-top: 5px;
            font-size: 12px;
            color: #666;
        }
        
        .strength-weak { color: #d32f2f; }
        .strength-medium { color: #f57c00; }
        .strength-strong { color: #388e3c; }
    </style>
</head>
<body>
    <div class="register-container">
        <div class="logo">知识库</div>
        <div class="subtitle">创建您的账户，开始知识管理之旅</div>
        
        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>
        
        <form action="/user/register" method="post" id="registerForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required placeholder="请输入用户名">
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required placeholder="请输入密码">
                <div class="password-strength" id="passwordStrength"></div>
            </div>
            
            <div class="form-group">
                <label for="confirmPassword">确认密码</label>
                <input type="password" id="confirmPassword" name="confirmPassword" required placeholder="请再次输入密码">
            </div>
            
            <div class="form-group">
                <label for="email">邮箱</label>
                <input type="email" id="email" name="email" required placeholder="请输入邮箱地址">
            </div>
            
            <button type="submit" class="register-btn" id="submitBtn">注册</button>
        </form>
        
        <div class="divider">或</div>
        
        <div class="login-link">
            已有账号？<a href="/user/login">立即登录</a>
        </div>
    </div>

    <script>
        document.getElementById('registerForm').onsubmit = function(e) {
            var password = document.getElementById('password').value;
            var confirmPassword = document.getElementById('confirmPassword').value;
            
            if(password !== confirmPassword) {
                alert('两次密码不一致');
                e.preventDefault();
                return false;
            }
            
            if(password.length < 6) {
                alert('密码长度至少6位');
                e.preventDefault();
                return false;
            }
        };
        
        // 密码强度检测
        document.getElementById('password').addEventListener('input', function() {
            var password = this.value;
            var strength = document.getElementById('passwordStrength');
            
            if(password.length === 0) {
                strength.textContent = '';
                return;
            }
            
            var score = 0;
            if(password.length >= 6) score++;
            if(/[a-z]/.test(password)) score++;
            if(/[A-Z]/.test(password)) score++;
            if(/[0-9]/.test(password)) score++;
            if(/[^A-Za-z0-9]/.test(password)) score++;
            
            if(score < 2) {
                strength.textContent = '密码强度：弱';
                strength.className = 'password-strength strength-weak';
            } else if(score < 4) {
                strength.textContent = '密码强度：中等';
                strength.className = 'password-strength strength-medium';
            } else {
                strength.textContent = '密码强度：强';
                strength.className = 'password-strength strength-strong';
            }
        });
    </script>
</body>
</html> 